package mvp.com.bbc.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import java.util.List;

import mvp.com.bbc.R;
import mvp.com.bbc.app.ApiUrls;
import mvp.com.bbc.appContact.AppContact;
import mvp.com.bbc.base.BaseFragment;
import mvp.com.bbc.bean.HotCoultBean;
import mvp.com.bbc.di.component.DaggerHotCoultComponent;
import mvp.com.bbc.di.modules.HotCoultModules;
import mvp.com.bbc.ui.presenter.HotCoultPresenter;

/**
 * Created by Administrator on 2017/9/29.
 */

public class HomeFragment extends BaseFragment implements AppContact.HotCoultView {

    private TextView mTvTitle;
    private WebView mTvContent;
    private HotCoultPresenter mPresenter;
    private final String url = ApiUrls.REQUSTE_HEADE + "information/informationDetail.do?informationId=" + 1 + "&type=information";

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        mTvTitle = (TextView) view.findViewById(R.id.tv_title);
        mTvContent = (WebView) view.findViewById(R.id.tv_content);
        mPresenter = DaggerHotCoultComponent.builder()
                .hotCoultModules(new HotCoultModules(this))
                .build()
                .getPresenter();
        mPresenter.hotCoultPresenter("1");
        WebSettings settings = mTvContent.getSettings();
        settings.setJavaScriptEnabled(true);
        mTvContent.loadUrl(url);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.home_fragment;
    }

    @Override
    public void HotCoulView(HotCoultBean hotCoultBean) {
        List<HotCoultBean.InListBean> inList = hotCoultBean.getInList();
        if (inList != null && inList.size() > 0) {
            for (int i = 0; i < inList.size(); i++) {
                HotCoultBean.InListBean inListBean = inList.get(i);
                mTvTitle.setText(inListBean.getTitle());
//                mTvContent.setText(inListBean.getContent());
            }
        }

    }
}
